
<template>
<el-upload
  v-model:file-list="fileList"
  class="upload-demo"
  :http-request="afterIDCardRead"
  multiple
>
  <el-button type="primary">Click to upload</el-button>
  <template #tip>
    <div class="el-upload__tip">
      仅支持 jpg/png 文件，最大 500KB，自动实名上传七牛
    </div>
  </template>
</el-upload>
</template>
<script setup>
import axios from 'axios';
import { ref,onMounted } from 'vue';
// import  http  from '../http'

const token=ref('')
const imgurl=ref('')
const fileList=ref([])
// 七牛云配置

const getqntoken=()=>{
  axios.get('http://127.0.0.1:8888/idcard/verify').then(res=>{
    token.value=res.data
    console.log(token.value);
    
  })
}

const afterIDCardRead= async(fileInfo)=>{
  const formData = new FormData();
  formData.append("file", fileInfo.file);
  formData.append("token", token.value);
  try {
    const res = await axios.post("https://upload-z2.qiniup.com", formData);
    console.log(res);
    
    const img_url = "http://t4vxr8qpc.hn-bkt.clouddn.com/" + res.data.key;
    const res1 = await axios.get("http://127.0.0.1:8888/idcard/redis1",{params:{url:img_url}});
    console.log(res1);
  } catch (error) {
    console.error("上传失败:", error.response?.data || error.message);
  }
}

onMounted(()=>{
  getqntoken()
})
</script>

<style scoped>
/* 可以添加一些样式来美化界面 */
</style>